package com.probiz.estoresa.content.web.action;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.validation.BindException;

import com.probiz.estore.common.model.content.AdPositionType;
import com.probiz.estore.content.service.AdPositionTypeManager;
import com.probiz.estore.core.controller.GenericStoreAdminController;


public class AdPositionTypeController extends GenericStoreAdminController<AdPositionType> {
    private AdPositionTypeManager adPositionTypeManager = null;

    public void setAdPositionTypeManager(AdPositionTypeManager adPositionTypeManager) {
        this.adPositionTypeManager = adPositionTypeManager;
    }

	@Override
	protected String getEntityName(AdPositionType entity) {
		return entity.getPositionName();
	}


	@Override
	protected void initController() throws Exception {
		this.mgr = adPositionTypeManager;
		
	}
	
	@Override
	protected Map<String,String> getSortMap(){
		Map<String,String> sortMap = new HashMap<String,String>();
		sortMap.put("0", "convert_gbk(positionName)");
		sortMap.put("1", "convert_gbk(positionCode)");
		sortMap.put("2", "width");
		sortMap.put("3", "displayType");
		return sortMap;
	}

	@Override
	protected void preSave(HttpServletRequest request, AdPositionType entity,
			BindException errors) {
		if(adPositionTypeManager.isExistPositionCode(entity.getPositionCode(), entity.getAdPositionTypeId())){
    		errors.rejectValue("positionCode","adPositionType.name.exists");
    	}
	}   
	
        
}
